package vista;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.util.*;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SpinnerListModel;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import modelo.Conexion;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FacturaV extends javax.swing.JFrame {
	private JPanel jPanel1;
	private JLabel jLabel3, jLabel4, jLabel5, jLabel9,
				   jLabel15, jLabel16, jLabel17, jLabel18, jLabel19;
	private JLabel nombre, apellido, direccion, total;
	private JButton bntIncluir, bntImprimir;
	private JLabel direcccliente;
	private JLabel apellcliente;
	private JLabel nombcliente;
	private JTextField txtrif;
	private JSeparator jSeparator3, jSeparator5, jSeparator6, jSeparator7;
	private JButton bntBuscar;
	private JLabel SubTotal;
	private JLabel jLabel10;
	private JLabel iva;
	private JLabel jLabel11;
	private JSeparator jSeparator4;
	private JSeparator jSeparator2;
	private JLabel jLabel14;
	private JSeparator jSeparator1;
	private JLabel fec;
	
	private JPanel FondoF;
	private JLabel jLabel13;
	private JLabel jLabel12;
	private JButton bntCancelar;
	private JButton bntSalir;
	private JScrollPane jScrollPane1;
	private JButton bntGuardar;
	private JLabel jLabel8;
	private JTextField txtcantidad;
	private JLabel jLabel7;
	private JLabel jLabel6;
	private JTable tablaproductos;
	private JComboBox comboCategoria,comboproducto;
	private JLabel jLabel2;
	private JLabel jLabel1;
	private JPanel jPanel2;
	int t = 0;
	boolean bool = false;
	private Object VAL[][];
	private final String[] MES = {"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"};
	public FacturaV() {
		super();
		initGUI();
	}
	public Object [][] GetDatos()
	{
		return VAL;
	}
	public int N_Elementos()
	{
		return t;
	}
    public void SetFecha(Date d)
    {
    	String S[] = new Date().toString().split(" ");
    	this.fec.setText(d.getDay() + " " + MES[d.getMonth()-1] + " " + S[5]);
    }
	
	public JLabel getTotal()
	{
		return total;
	}
	public void setTotal(String x)
	{
		this.total.setText(x);
	}
	public JLabel getSubTotal() 
	{
		return SubTotal;
	}
	public void setSubTotal(String x) 
	{
		SubTotal.setText(x);
	}
	public JLabel getIva()
	{
		return iva;
	}
	public void setIva(String x) 
	{
		this.iva.setText(x);
	}
	public void setTxtRif(String x){
		txtrif.setText(x);
	}
	public JTextField getTxtRif(){
		return txtrif;
	}
	
	public void setNombre(String x){
		nombre.setText(x);
	}
	public void setApellido(String x){
		apellido.setText(x);
	}
	public void VaciarDatos()
	{
		VAL = new Object[0][0];
		t = 0;
		bool = false;
	}
	////////////////////////////////////////////////
	public void Anadir(List<Object>L)
	{
		
		Object[][]aux  = new Object[++t][5];
		for(int i = 0;i < t-1;i++)
			for(int j = 0;j < 5;j++)
				aux[i][j] = VAL[i][j];

		
		for(int i = 0;i < 5;i++)
			aux[t-1][i] = L.get(i);
		
		
		VAL  = new Object[t][5];
		for(int i = 0;i < t;i++)
			for(int j = 0;j < 5;j++)
				VAL[i][j] = aux[i][j];
		t = bool == true ? t : 0;
		bool = true;
		CargarTabla();
	}
	public void CargarTabla()
	{
		TableModel jTable1Model = 
		new DefaultTableModel
		(VAL,new String[] { "Categorias","  Productos  ", " Precio "," Cantidad "," Sub Total "  });
		
		tablaproductos = new JTable();
		jScrollPane1.setViewportView(tablaproductos);
		tablaproductos.setModel(jTable1Model);
		tablaproductos.setBounds(71, 308, 457, 35);
		tablaproductos.setShowVerticalLines(false);
		tablaproductos.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
		tablaproductos.setToolTipText("");
		tablaproductos.setOpaque(false);
		tablaproductos.setPreferredSize(new java.awt.Dimension(601, 149));
	}
	public JComboBox GetcomboCategoria()
	{
	   return comboCategoria;
    }
	public void SetcomboCategoria(int i)
	{
		comboCategoria.setSelectedIndex(i);
    }
	public void SetcomboCategoria(String str)
	{
		ComboBoxModel modelo = new DefaultComboBoxModel(str.split(","));
		comboCategoria.setModel(modelo);
    }
	//---------
	public JComboBox Getcomboproducto()
	{
	   return comboproducto;
    }
	public void Setcomboproducto(int i)
	{
		comboproducto.setSelectedIndex(i);
    }
	public void Setcomboproducto(String str)
	{
		ComboBoxModel modelo = new DefaultComboBoxModel(str.split(","));
		comboproducto.setModel(modelo);
    }
	public void SetNumero(int n)
	{
		jLabel5.setText("000"+n);
	}
	public JLabel GetNumero()
	{
		return jLabel5;
	}
	public JTextField GetTxtcantidad()
	{
		return txtcantidad;
	}
	public void SetTxtcantidad(int n)
	{
		txtcantidad.setText(""+n);
	}
	
	////////////////////////////////////////////////////
	public void addKeyListener(KeyListener kl)
	{
		txtcantidad.addKeyListener(kl);
	}
	public void addListener(ActionListener actionListener)
	{
		this.bntBuscar.addActionListener(actionListener);
		this.bntGuardar.addActionListener(actionListener);
		this.bntCancelar.addActionListener(actionListener);
		this.bntSalir.addActionListener(actionListener);
		this.bntImprimir.addActionListener(actionListener);
		this.comboCategoria.addActionListener(actionListener);
		this.bntIncluir.addActionListener(actionListener);
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(Color.white);
			this.setTitle("Factura de Venta");
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1);
				getContentPane().add(jPanel1).setBackground(Color.white);
				jPanel1.setBounds(19, 22, 646, 597);
				jPanel1.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				jPanel1.setLayout(null);
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("Establecimiento de Comida Rapida JJA. C.A");
					jLabel1.setBounds(18, 17, 405, 24);
					jLabel1.setFont(new java.awt.Font("Purisa",0,16));
				}
				{
					jLabel2 = new JLabel();
					jPanel1.add(jLabel2);
					jLabel2.setText("Cabudare - Estado Lara");
					jLabel2.setBounds(100, 59, 224, 19);
					jLabel2.setFont(new java.awt.Font("Purisa",0,16));
				}
				{
					jLabel3 = new JLabel();
					jPanel1.add(jLabel3);
					jLabel3.setText("R.I.F J-25165464-0   N.I.T 41026546");
					jLabel3.setBounds(40, 37, 347, 21);
					jLabel3.setFont(new java.awt.Font("Purisa",0,16));
				}
				{
					jLabel4 = new JLabel();
					jPanel1.add(jLabel4);
					jLabel4.setText("Tlf: 0251-2563985");
					jLabel4.setBounds(142, 80, 145, 20);
					jLabel4.setFont(new java.awt.Font("Purisa",0,14));
				}
				{
					comboCategoria = new JComboBox();
					jPanel1.add(comboCategoria);
					comboCategoria.setBounds(89, 262, 146, 26);
					comboCategoria.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					comboproducto = new JComboBox();
					jPanel1.add(comboproducto);
					comboproducto.setBounds(319, 262, 146, 26);
					comboproducto.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					jLabel6 = new JLabel();
					jPanel1.add(jLabel6);
					jLabel6.setText("Categorias");
					jLabel6.setBounds(12, 262, 81, 26);
					jLabel6.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					jLabel7 = new JLabel();
					jPanel1.add(jLabel7);
					jLabel7.setText("Productos");
					jLabel7.setBounds(244, 262, 75, 26);
					jLabel7.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					txtcantidad = new JTextField();
					jPanel1.add(txtcantidad);
					txtcantidad.setBounds(541, 262, 38, 26);
				}
				{
					jLabel8 = new JLabel();
					jPanel1.add(jLabel8);
					jLabel8.setText("Lista de Producto ");
					jLabel8.setBounds(215, 319, 171, 19);
					jLabel8.setFont(new java.awt.Font("Purisa",1,14));
				}
				{
					bntIncluir = new JButton();
					jPanel1.add(bntIncluir);
					bntIncluir.setText("I");
					bntIncluir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/aceptar.png")));
					bntIncluir.setFont(new java.awt.Font("Dialog",0,11));
					bntIncluir.setBounds(583, 258, 56, 32);
				}
				{
					jScrollPane1 = new JScrollPane();
					jPanel1.add(jScrollPane1);
					jScrollPane1.setBounds(14, 350, 610, 150);
				}
				{
					FondoF = new JPanel();
					jPanel1.add(FondoF);
					FondoF.setBounds(438, 0, 208, 104);
					FondoF.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					FondoF.setLayout(null);
					{
						jLabel13 = new JLabel();
						FondoF.add(jLabel13);
						jLabel13.setText("Fecha:");
						jLabel13.setFont(new java.awt.Font("Purisa",1,14));
						jLabel13.setBounds(19, 26, 50, 25);
					}
					{
						jLabel12 = new JLabel();
						FondoF.add(jLabel12);
						jLabel12.setText("N° de Control:");
						jLabel12.setFont(new java.awt.Font("Purisa",1,12));
						jLabel12.setBounds(21, 61, 103, 21);
					}
					{
						jLabel5 = new JLabel();
						FondoF.add(jLabel5);
						jLabel5.setText("Factura N° de Control");
						jLabel5.setFont(new java.awt.Font("Purisa",1,14));
						jLabel5.setBounds(136, 59, 48, 25);
					}
					{
						fec = new JLabel();
						FondoF.add(getFec());
						fec.setBounds(73, 27, 132, 26);
						fec.setFont(new java.awt.Font("Purisa",1,14));
					}
				}
				{
					jSeparator1 = new JSeparator();
					jPanel1.add(jSeparator1);
					jSeparator1.setBounds(215, 153, 245, 13);
				}
				{
					jLabel14 = new JLabel();
					jPanel1.add(jLabel14);
					jLabel14.setText("Factura de Venta");
					jLabel14.setFont(new java.awt.Font("Purisa",1,20));
					jLabel14.setBounds(229, 125, 229, 26);
				}
				{
					jSeparator2 = new JSeparator();
					jPanel1.add(jSeparator2);
					jSeparator2.setBounds(2, 102, 436, 10);
				}
				{
					total = new JLabel();
					jPanel1.add(total);
					total.setBounds(527, 560, 88, 23);
				}
				{
					jSeparator4 = new JSeparator();
					jPanel1.add(jSeparator4);
					jSeparator4.setBounds(512, 560, 84, 12);
				}
				{
					jLabel11 = new JLabel();
					jPanel1.add(jLabel11);
					jLabel11.setText("Total:");
					jLabel11.setFont(new java.awt.Font("Dialog",0,14));
					jLabel11.setBounds(471, 560, 48, 23);
				}
				{
					iva = new JLabel();
					jPanel1.add(iva);
					iva.setBounds(528, 537, 75, 23);
				}
				{
					jLabel10 = new JLabel();
					jPanel1.add(jLabel10);
					jLabel10.setText("I.V.A 12%");
					jLabel10.setFont(new java.awt.Font("Dialog",0,14));
					jLabel10.setBounds(442, 537, 70, 23);
				}
				{
					SubTotal = new JLabel();
					jPanel1.add(SubTotal);
					SubTotal.setBounds(529, 514, 72, 23);
				}
				{
					jLabel9 = new JLabel();
					jPanel1.add(jLabel9);
					jLabel9.setText("Sub-Total:");
					jLabel9.setFont(new java.awt.Font("Dialog",0,14));
					jLabel9.setBounds(441, 514, 71, 23);
				}
				{
					jSeparator3 = new JSeparator();
					jPanel1.add(jSeparator3);
					jSeparator3.setBounds(2, 297, 642, 10);
				}
				{
					jSeparator5 = new JSeparator();
					jPanel1.add(jSeparator5);
					jSeparator5.setBounds(2, 251, 642, 7);
				}
				{
					bntBuscar = new JButton();
					jPanel1.add(bntBuscar);
					bntBuscar.setText("B");
					bntBuscar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/buscar1.png")));
					bntBuscar.setDoubleBuffered(false);
					bntBuscar.setBounds(236, 175, 57, 33);
					bntBuscar.setFocusCycleRoot(false);
				}
				{
					jSeparator6 = new JSeparator();
					jPanel1.add(jSeparator6);
					jSeparator6.setBounds(2, 211, 641, 11);
				}
				{
					jLabel15 = new JLabel();
					jPanel1.add(jLabel15);
					jLabel15.setText("Rif. Cliente");
					jLabel15.setFont(new java.awt.Font("Dialog",0,14));
					jLabel15.setBounds(12, 179, 88, 26);
				}
				{
					txtrif = new JTextField();
					jPanel1.add(txtrif);
					txtrif.setFont(new java.awt.Font("Dialog",0,14));
					txtrif.setBounds(106, 178, 124, 26);
				}
				{
					jSeparator7 = new JSeparator();
					jPanel1.add(jSeparator7);
					jSeparator7.setBounds(2, 170, 642, 7);
				}
				{
					jLabel16 = new JLabel();
					jPanel1.add(jLabel16);
					jLabel16.setText("Cantidad");
					jLabel16.setBounds(473, 262, 65, 26);
					jLabel16.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					jLabel17 = new JLabel();
					jPanel1.add(jLabel17);
					jLabel17.setText("Nombre: ");
					jLabel17.setBounds(12, 219, 64, 26);
					jLabel17.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					nombre = new JLabel();
					jPanel1.add(getNombre());
					nombre.setBounds(90, 219, 130, 26);
					nombre.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					jLabel18 = new JLabel();
					jPanel1.add(jLabel18);
					jLabel18.setText("Apellido");
					jLabel18.setBounds(236, 220, 59, 26);
					jLabel18.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					apellido = new JLabel();
					jPanel1.add(getApellido());
					apellido.setBounds(301, 219, 134, 26);
					apellido.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					jLabel19 = new JLabel();
					jPanel1.add(jLabel19);
					jLabel19.setText("Direccion");
					jLabel19.setBounds(429, 218, 75, 26);
					jLabel19.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					nombcliente = new JLabel();
					jPanel1.add(nombcliente);
					nombcliente.setBounds(88, 225, 136, 10);
				}
				{
					apellcliente = new JLabel();
					jPanel1.add(apellcliente);
					apellcliente.setBounds(302, 226, 110, 10);
				}
				{
					direcccliente = new JLabel();
					jPanel1.add(direcccliente);
					direcccliente.setBounds(503, 224, 124, 10);
				}
			}
			{
				jPanel2 = new JPanel();
				getContentPane().add(jPanel2);
				jPanel2.setBounds(82, 631, 504, 56);
				jPanel2.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				jPanel2.setLayout(null);
				{
					bntGuardar = new JButton();
					jPanel2.add(bntGuardar);
					bntGuardar.setText("Guardar");
					bntGuardar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/aceptar.png")));
					bntGuardar.setFont(new java.awt.Font("Dialog",0,11));
					bntGuardar.setBounds(14, 8, 113, 39);
				}
				{
					bntImprimir = new JButton();
					jPanel2.add(bntImprimir);
					bntImprimir.setText("Imprimir");
					bntImprimir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/imprimir.png")));
					bntImprimir.setBounds(141, 8, 114, 39);
				}

				{
					bntCancelar = new JButton();
					jPanel2.add(bntCancelar);
					bntCancelar.setText("Cancelar");
					bntCancelar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/eliminar.png")));
					bntCancelar.setFont(new java.awt.Font("Dialog",0,11));
					bntCancelar.setBounds(268, 8, 115, 39);
				}
				{
					bntSalir = new JButton();
					jPanel2.add(bntSalir);
					bntSalir.setText("Salir");
					bntSalir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/salir1.png")));
					bntSalir.setBounds(396, 8, 94, 40);
				}
			}
			pack();
			this.setSize(687, 731);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public JLabel getDirecccliente()
	{
		return direcccliente;
	}
	public void setDirecccliente(String str) 
    {
		this.direcccliente.setText(str);
	}
	public JLabel getApellcliente() {
		return apellcliente;
	}
	public void setApellcliente(String str)
	{
		this.apellcliente.setText(str);
	}
	public JLabel getNombcliente() 
    {
		return nombcliente;
	}
	public void setNombcliente(String str)
	{
		this.nombcliente.setText(str);
	}
	public JLabel getFec() 
	{
		return fec;
	}	
	public JLabel getNombre() 
	{
		return nombre;
	}
	public JLabel getApellido() 
	{
		return apellido;
	}
	public JLabel getDireccion() 
	{
		return direccion;
	}
	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}

}
